// 封装请求方法

import base from "@/utils/baseURL.js"

module.exports.get = function(src, data={}) {
	let token = uni.getStorageSync('token')
	return new Promise((resolve,reject)=>{
		uni.request({
			method:'GET',
			header: {
				"token": token
			},
			url: base.baseURL + src,
			data: data,
			success: (res) => {
				if(res.data.code==1){
					resolve(res.data.data)
				}else{
					uni.$u.toast(res.data.msg)
					reject(res.data)
				}
			},
			fail: (err) => {
				uni.$u.toast(err)
			}
		})
	})
}

// post 请求
module.exports.post = function(src, data={}) {
	let token = uni.getStorageSync('token')
	return new Promise((resolve,reject)=>{
		uni.request({
			method:'POST',
			header: {
				"token": token
			},
			url: base.baseURL + src,
			data: data,
			success: (res) => {
				if(res.data.code==1){
					resolve(res.data.data)
				}else{
					uni.$u.toast(res.data.msg)
					reject(res.data)
				}
			},
			fail: (err) => {
				uni.$u.toast(err)
			}
		})
	})
	
}